<template>
	<view class="main-wrap">
		<view v-if="!loading">
			<TopContent :message="message" :logo="logo" />
			<view class="content">
				<view class="navigation-content">
					<block v-for="(item,index) in navArray" :key="index">
						<view class="nav-item-con">
							<view class="item-con-title-wrap flex rcs">
								<view class="line-style vertical-line con-title-line"></view>
								<text class="item-con-title">{{item.name}}</text>
							</view>
							<view class="sub-nav-content grid col-4">
								<block v-for="(obj,_index) in item.data" :key="_index">
									<view class="sub-nav-item flex ccc" @tap="onPressNavItem(obj)">
										<image class="sub-nav-icon" :src="obj.icon" mode='widthFix' />
										<text class="sub-nav-title">{{obj.name}}</text>
									</view>
								</block>
							</view>
						</view>
					</block>
				</view>
			</view>
			<view class="cu-modal bottom-modal" :class="showAddActions ?'show':''" @touchmove.stop.prevent="" @tap="onShowAddActions">
				<view class="cu-dialog">
					<view class="cu-bar bg-white flex rce">
						<view class="action text-blue" @tap.stop="onShowAddActions">取消</view>
					</view>
					<view class="padding-xl action-content">
						<view class="action-title">—— 请选择添加人才的方式 ——</view>
						<view class="action-content-detail grid col-3">
							<block v-for="(item, index) in addTalentNavArray" :key="index">
								<view @tap.stop="onPressNavItem(item)" class="flex flex-1 action-con-item ccc">
									<image class="action-item-icon" :src="item.icon" mode="widthFix" />
									<text class="action-item-title">{{item.title}}</text>
								</view>
							</block>
						</view>
					</view>
				</view>
			</view>
		</view>
		<Loading v-else />
		<view class="cu-modal show" v-if="showConfirm">
			<view class="cu-dialog dialog-container">
				<view class="cu-bar dialog-title-view flex rcb">
					<view class="dialog-title-style">温馨提示</view>
					<view class="dialog-btn-close" @tap="onPressCancel">
						<text class="cuIcon-close"></text>
					</view>
				</view>
				<view class="dialog-content-view flex ccc">
					<view class="dialog-context flex ccc">确定要退出吗？</view>
				</view>
				<view class="cu-bar dialog-btn-wrap flex rcb">
					<view class="btn-item btn-cancel-item flex ccc" @tap="onPressCancel">取消</view>
					<view class="btn-item btn-submit-item flex ccc" @tap="onPressSubmit">确定</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	// import jweixin from '../../common/wechat-sdk.js'
	// import jweixin from 'jweixin-module';
	import aliOss from '../../components/ali-oos/ali-oos/index.js'
	import TopContent from '../../components/work_bench/work_bench_top_content.vue'
	import Loading from '../../components/common/loading.vue'
	export default {
		components: {
			Loading,
			TopContent,
		},
		data() {
			return {
				qr_code: '',
				loading: true,
				token: '',
				showConfirm: false,
				showAddActions: false,
				Images: this.Images,
				logo: '../../static/img/img_logo.png',
				message: [{
						"num": 0,
						"name": "人才数",
						"type": '/pages/talent_pool/index',
						"component": 'navigate',
					},
					{
						"num": 0,
						"name": "任务数",
						"type": 'navigate',
						"component": '/pages/company/companyManagerList'
					},
					{
						"num": 0,
						"name": "专员数",
						"type": 'navigate',
						"component": '/pages/work_bench/positionTaskList'
					},
					{
						"num": 0,
						"name": "未入职",
						"type": '/pages/talent_pool/index',
						"component": 'navigate',
					},
					{
						"num": 0,
						"name": "待入职",
						"type": 'navigate',
						"component": '/pages/company/companyManagerList'
					},
					{
						"num": 0,
						"name": "在职",
						"type": 'navigate',
						"component": '/pages/work_bench/positionTaskList'
					}
				],
				weather: {
					city: '青岛',
					weather: '小雨',
					type: 1, // 根据类型展示图标
				},
				addTalentNavArray: [{
					title: '扫描身份证正面',
					icon: '/static/icon/icon_btn_scan.png',
					component: 'scan_id_card',
					type: 'foo'
				}, {
					title: '上传身份证',
					icon: '/static/icon/icon_btn_camera.png',
					component: '/pages/publish/talent_add_upload',
					type: 'navigate'
				}, {
					title: '手动录入',
					icon: '/static/icon/icon_btn_edit.png',
					component: '/pages/publish/talent_add_manual',
					type: 'navigate'
				}, ],
				navArray: [{
						name: '招聘管理',
						data: [{
								name: '招聘任务',
								icon: '/static/icon/icon_work_bench_nav7.png',
								component: '/pages/work_bench/positionTaskList',
								type: 'navigate'
							},
							{
								name: '招聘小组',
								icon: '/static/icon/icon_work_bench_nav6.png',
								component: '/pages/recruitment/recruitTeamList',
								type: 'navigate'
							},
							{
								name: '个人任务',
								icon: '/static/icon/icon_work_bench_nav15.png',
								component: '/pages/work_bench/positionTaskList?is_personal=yes&page_flag=' + this.Constants.PERSONAL_TASK,
								type: 'navigate'
							},
							{
								name: '招聘选项',
								icon: '/static/icon/icon_work_bench_nav8.png',
								component: '/pages/recruitment/recruitmentOptions',
								type: 'navigate'
							},
						]
					},
					{
						name: '人才管理',
						data: [{
								name: '添加人才',
								icon: '/static/icon/icon_work_bench_nav1.png',
								// component: '/pages/publish/talent_add_manual',
								component: 'addTalent',
								type: 'foo'
							},
							{
								name: '人才库',
								icon: '/static/icon/icon_work_bench_nav2.png',
								component: 'switchTab',
								type: 'foo'
							},
							// {
							// 	name: '数据统计',
							// 	icon: '/static/icon/icon_work_bench_nav3.png',
							// 	component: '/pages/work_bench/data_statistics',
							// 	type: 'navigate'
							// },
							{
								name: '简历来源',
								icon: '/static/icon/icon_work_bench_nav4.png',
								component: '/pages/work_bench/channelSourceList',
								type: 'navigate'
							},
						]
					},
					{
						name: '驻厂管理',
						data: [{
								name: '我的驻企',
								icon: '/static/icon/icon_work_bench_nav9.png',
								component: '/pages/work_bench/myCompanyList',
								type: 'navigate'
							},
							{
								name: '管理选项',
								icon: '/static/icon/icon_work_bench_nav10.png',
								component: '/pages/company/companyOptions',
								type: 'navigate'
							},
							{
								name: '驻企管理',
								icon: '/static/icon/icon_work_bench_nav16.png',
								component: '/pages/work_bench/stationManage',
								type: 'navigate'
							},
							{
								name: '企业管理',
								icon: '/static/icon/icon_work_bench_nav9.png',
								component: '/pages/company/companyManagerList',
								type: 'navigate'
							},
						]
					},
					{
						name: '设置',
						data: [{
								name: '修改密码',
								icon: '/static/icon/icon_work_bench_nav11.png',
								component: '/pages/login/modify_password',
								type: 'navigate'
							},
							{
								name: '联系客服',
								icon: '/static/icon/icon_work_bench_nav14.png',
								component: '/pages/system/system_customer',
								type: 'navigate'
							},
							{
								name: '退出登录',
								icon: '/static/icon/icon_work_bench_nav13.png',
								component: 'onLogout',
								type: 'foo'
							},
						]
					}
				]
			};
		},
		onShow() {
			uni.onTabBarMidButtonTap(() => {
				console.log('onTabBarMidButtonTap---->', 'onTabBarMidButtonTap');
				this.onShowAddActions();
			})
		},
		onLoad() {
			this.requestWorkBenchCount();
			this.requestWorkBenchMenu();
			this.requestWorkBenchLogo();
			// this.initialWeChatSdk({});
		},
		methods: {
			async initialWeChatSdk(detail) {
				var ua = window.navigator.userAgent.toLowerCase();
				if (ua.match(/micromessenger/i) == 'micromessenger') {
					console.log('微信客户端---->', 'true');
					let url = this.ServicesApi.get_share_config; // 'http://rencaiku.renkeyun.cn/wechat/index/share?tenant_id=&id=0'
					let data = {
						url: 'http://rencaiku.renkeyun.cn/h5/#', // encodeURIComponent(window.location.href.split('#')[0]), //获取当前url然后传递给后台获取授权和签名信息
					};
					let result = await this.Services.post(url, data);
					if (result.code == this.StatusCode.SUCCESS_CODE || result.code == 20000) {
						console.log('result.data---->', result.data);
						//返回需要的参数appId,timestamp,noncestr,signature等  
						//注入config权限配置  
						// jweixin.config({
						// 	debug: false,
						// 	appId: result.data.appId,
						// 	timestamp: result.data.timestamp,
						// 	nonceStr: result.data.nonceStr,
						// 	signature: result.data.signature,
						// 	jsApiList: [ //这里是需要用到的接口名称
						// 		'updateAppMessageShareData',
						// 		'updateTimelineShareData'
						// 	]
						// });
						// wx.ready(function() {
						// 	//分享给朋友
						// 	wx.updateAppMessageShareData({
						// 		title: 'detail.name',
						// 		desc: detail.remark,
						// 		link: detail.show_img_link,
						// 		imgUrl: detail.share_logo,
						// 		success: function(res) {
						// 			console.log('res---->', res);
						// 		}
						// 	});
						// 	//分享到朋友圈
						// 	wx.updateTimelineShareData({
						// 		title: 'detail.name',
						// 		link: detail.show_img_link,
						// 		imgUrl: detail.share_logo,
						// 		desc: detail.remark,
						// 		success: function(res) {
						// 			console.log('res---->', res);
						// 		}
						// 	});
						// });
					}
				}
			},
			onPressCancel() {
				this.showConfirm = false;
			},
			async onPressSubmit() {
				uni.reLaunch({
					url: '/pages/login/login'
				});
				uni.clearStorage();
			},
			async getQrCode() {
				let url = this.ServicesApi.getQrCodeImg;
				let data = {
					id: 260,
				};
				let result = await this.Services.post(url, data);
				if (result.code == this.StatusCode.SUCCESS_CODE) {
					this.qr_code = result.data;
				}
			},
			// 取token
			getToken() {
				// console.log('this.LocalStore.token---->', this.LocalStore.token);
				// try {
				// 	// console.log(this.Images);
				// 	const value = uni.getStorageSync('login_key');
				// 	if (value) {
				// 		this.token = value;
				// 	}
				// } catch (e) {
				// 	// error
				// }
			},
			async requestWorkBenchLogo() {
				let url = this.ServicesApi.work_bench_logo;
				let data = {};
				let result = await this.Services.post(url, data);
				if (result.code == this.StatusCode.SUCCESS_CODE) {
					this.logo = result.data.logo;
				}
				// console.log('requestWorkBenchCount---->', result);
			},
			async requestWorkBenchCount() {
				// console.log('requestWorkBenchCount---->', 'requestWorkBenchCount');
				let url = this.ServicesApi.work_bench_count;
				let data = {};
				let result = await this.Services.post(url, data);
				if (result.code == this.StatusCode.SUCCESS_CODE) {
					this.message = result.data;
				}
				// console.log('requestWorkBenchCount---->', result);
			},
			async requestWorkBenchMenu() {
				// console.log('requestWorkBenchCount---->', 'requestWorkBenchCount');
				let url = this.ServicesApi.check_auth;
				let data = {};
				let result = await this.Services.post(url, data);
				if (result.code == this.StatusCode.SUCCESS_CODE) {
					this.navArray = result.data;
				}
				setTimeout(() => this.loading = false, 200);
			},
			onPressNavItem(item) {
				console.log('onPressNavItem---->', item);
				this.showAddActions = false;
				if (item.type === 'navigate' && item.component !== '') {
					uni.navigateTo({
						url: item.component,
					});
				} else if (item.type === 'foo') {
					console.log('item.component---->', item.component);
					switch (item.component) {
						case 'onClearStorage':
							this.onClearStorage();
							break;
						case 'onLogout':
							this.onLogout();
							break;
						case 'switchTab':
							console.log('item.component---->', item.component);
							uni.switchTab({
								url: "/pages/talent_pool/index",
							})
							break;
						case 'scan_id_card':
							this.onScanIdCardImage();
							// this.onScanIdCardImageTest();
							break;
						case 'addTalent':
							this.onShowAddActions();
							break;
						default:
							break;
					}
				}
			},
			async onScanIdCardImageTest() {
				let res = {
					"msg": "获取成功",
					"data": {
						"住址": {
							"location": {
								"width": 169,
								"top": 353,
								"left": 103,
								"height": 39
							},
							"words": "山东省诸城市龙都街道邱家七吉村540号"
						},
						"出生": {
							"location": {
								"width": 119,
								"top": 321,
								"left": 104,
								"height": 15
							},
							"words": "19931215"
						},
						"姓名": {
							"location": {
								"width": 44,
								"top": 253,
								"left": 106,
								"height": 17
							},
							"words": "丌炜"
						},
						"公民身份号码": {
							"location": {
								"width": 222,
								"top": 435,
								"left": 167,
								"height": 19
							},
							"words": "370782199312150815"
						},
						"性别": {
							"location": {
								"width": 13,
								"top": 289,
								"left": 105,
								"height": 15
							},
							"words": "男"
						},
						"民族": {
							"location": {
								"width": 13,
								"top": 291,
								"left": 187,
								"height": 14
							},
							"words": "汉"
						}
					},
					"code": 1
				};
				let up_res = {
					data: [{
						name_server: "1571051343014.png",
						path: "http://tmp/touristappid.o6zAJs9KGG9ER0ZQI1d0WOrgziiM.69stymShp2e036050103abd4f0ebdfe2ffb85212157f.png",
						path_server: "http://talent-pool.oss-cn-qingdao.aliyuncs.com/talent-pool/1571051343014.png",
						size: 2618997,
						upload_percent: 0
					}]
				};
				uni.showToast({
					icon: 'none',
				    title: '识别成功',
				});
				let userInfoData = encodeURIComponent(JSON.stringify(res.data));
				let cardFrontInfo = encodeURIComponent(JSON.stringify(up_res.data[0]));
				uni.navigateTo({
					url: '/pages/publish/talent_add_manual?userInfoData=' + userInfoData + '&cardFrontInfo=' + cardFrontInfo,
				});
			},
			async onScanIdCardImage() {
				let options = {
					count: 1,
					sourceType: 'camera'
				}
				let _res = await aliOss.chooseImage(options);
				if (_res.code == this.StatusCode.SUCCESS_CODE) {
					let up_res = await aliOss.uploadImage(_res.data);
					if (up_res.code === 1) {
						let url = this.ServicesApi.getIdCardDetail;
						let data = {
							license: up_res.data[0].path_server
						};
						uni.showLoading({
							title: '识别中...'
						});
						let result = await this.Services.post(url, data);
						uni.hideLoading();
						if (result.code == this.StatusCode.SUCCESS_CODE) {
							uni.showToast({
								icon: 'none',
								title: '识别成功',
							});
							let userInfoData = encodeURIComponent(JSON.stringify(result.data));
							let cardFrontInfo = encodeURIComponent(JSON.stringify(up_res.data[0]));
							uni.navigateTo({
								url: '/pages/publish/talent_add_manual?userInfoData=' + userInfoData + '&cardFrontInfo=' +
									cardFrontInfo,
							});
						} else {
							uni.showToast({
								icon: 'none',
								title: '身份证识别失败，请重试',
							});
						}
					}
				}
			},
			onShowAddActions() {
				// console.log('showAddActions---->', 'showAddActions');
				this.showAddActions = !this.showAddActions;
			},
			onClearStorage() {
				uni.showModal({
					title: '温馨提示',
					content: '是否要清除缓存',
					showCancel: true,
					cancelText: '取消',
					confirmText: '确认',
					success: res => {
						if (res.confirm) {
							uni.clearStorage();
							uni.showToast({
								icon: 'none',
								title: '清除成功'
							});
						} else if (res.cancel) {

						}

					}
				});
			},
			// 退出
			onLogout() {
				this.showConfirm = true;
				return;
				this.getToken()
				// console.log(this.token)
				// 退出请求
				uni.showModal({
					title: '温馨提示',
					content: '确认要退出登录吗？',
					showCancel: true,
					cancelText: '取消',
					confirmText: '确认',
					success: res => {
						if (res.confirm) {
							uni.reLaunch({
								url: '/pages/login/login'
							});
							uni.clearStorage();
							uni.showToast({
								icon: 'none',
								title: '退出成功'
							})

							// uni.request({
							// 	url: this.ServicesApi.logOut,
							// 	method: 'POST',
							// 	header: {
							// 		"content-type": "application/x-www-form-urlencoded"
							// 	},
							// 	data: {
							// 		token: this.token,
							// 	},
							// 	success: (res) => {
							// 		// console.log(res.data);
							// 		if (res.data.code == 0) {
							// 			uni.reLaunch({
							// 				url: '/pages/login/login'
							// 			});
							// 			return false
							// 		} else {
							// 			try {
							// 				uni.clearStorage();
							// 			} catch (e) {
							// 				// error
							// 			}
							// 			// uni.navigateTo({
							// 			//     url: '/pages/login/login'
							// 			// });
							// 			uni.reLaunch({
							// 				url: '/pages/login/login'
							// 			});
							// 			uni.showToast({
							// 				title: '退出成功'
							// 			})
							// 		}
							// 	}
							// });
						} else if (res.cancel) {
							// uni.showToast({
							// 	title: '取消退出'
							// });
						}
					}
				});
			}
		}
	};
</script>

<style scoped>
	.content {
		overflow: hidden;
		padding: 0 30rpx 30rpx;
		background-color: #FFFFFF;
	}

	.message-content {
		position: relative;
		border-radius: 8upx;
		padding: 40upx 30upx;
		/* background-color: #007AFF; */
		background-image: url('~@/static/img/img_bg_message.png');
		background-size: 100% auto;
	}

	.message-content-bg {
		position: absolute;
		width: 100%;
		height: 100%;
		top: 0;
		left: 0;
		z-index: 0;
	}

	.message-line {
		margin: 0 20upx;
		background-color: #FFFFFF;
	}

	.message-item {
		flex: 1;
		text-align: center;
	}

	.message-con {
		color: #FFFFFF;
		font-size: 30upx;
		font-weight: 500;
	}

	.message-title {
		color: #FFFFFF;
		font-size: 26upx;
		margin-top: 10upx;
	}

	.weather-icon {
		width: 100upx;
		height: 100upx;
	}

	.weather-info {
		color: #FFFFFF;
	}

	.navigation-content {
		margin-top: 40rpx;
	}

	.nav-item-con {
		margin: 20upx 0;
	}

	.item-con-title-wrap {}

	.con-title-line {
		width: 8upx;
		height: 30upx;
		margin-right: 8upx;
		background-color: #9BC9FF;
	}

	.item-con-title {
		color: #333333;
		font-size: 30upx;
	}

	.sub-nav-content {
		flex-wrap: wrap;
	}

	.sub-nav-item {
		margin: 20upx 0;
	}

	.sub-nav-icon {
		width: 80upx;
		height: 80upx;
		object-fit: contain;
	}

	.sub-nav-title {
		color: #333333;
		font-size: 28upx;
		margin-top: 16upx;
	}


	.action-content {
		padding-top: 0;
		background-color: #FFFFFF;
	}

	.action-content .action-title {
		color: #666666;
		font-size: 30upx;
	}

	.action-content .action-content-detail {
		margin: 60upx 0;
	}

	.action-content .action-con-item {}

	.action-content .action-con-item .action-item-icon {
		width: 80upx;
		height: 80upx;
		margin-bottom: 20upx;
	}
</style>
